
#ifndef LIBRBTREE_QUEUE_H
#define LIBRBTREE_QUEUE_H
#include "librbtree.h"
#include "locker.h"
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif


#ifndef g_malloc
#define g_malloc malloc
#endif

#ifndef g_free
#define g_free free
#endif

#ifndef true
#define true 1
#endif

#ifndef false
#define false 0
#endif

typedef struct __rbqueue_node_t{
    struct rb_node node;
    char* key;
    char* priv_data;
}rbqueue_node_t,*rbqueue_node_ref_t;

typedef struct __rbtree_queue_t{
    struct rb_root root_node;

    locker_t lock;
    int size;
}rbtree_queue_t,*rbtree_queue_ref_t;


#define  RB_QUEUE_EMPTY_ROOT(queue)     RB_EMPTY_ROOT(&((queue)->root_node))
#define  RB_QUEUE_SIZE(queue)           ((queue)->size)
#define  RB_QUEUE_LOCK(queue)           {locker_lock(&((queue)->lock));}
#define  RB_QUEUE_UNLOCK(queue)         {locker_unlock(&((queue)->lock));}



int rbtree_queue_init(rbtree_queue_ref_t queue_root);
int rbtree_queue_deinit(rbtree_queue_ref_t queue_root);
//插入数据
int rbtree_queue_insert(rbtree_queue_ref_t queue_root,
    char *in_key,void *data);
//查找节点
rbqueue_node_t *rbtree_queue_search_node(rbtree_queue_ref_t queue_root,
     char *in_key);
//查找数据
void* rbtree_queue_search(rbtree_queue_ref_t queue_root,
     char *in_key);
//根据key删除节点
int rbtree_queue_erase(rbtree_queue_ref_t queue_root,
     char *in_key);

rbqueue_node_t *rbtree_queue_first_node(rbtree_queue_ref_t queue_root);
rbqueue_node_t *rbtree_queue_prev_node(rbqueue_node_t *p_queue_node);
rbqueue_node_t *rbtree_queue_next_node(rbqueue_node_t *p_queue_node);
rbqueue_node_t *rbtree_queue_last_node(rbtree_queue_ref_t queue_root);
#ifdef __cplusplus
}
#endif
#endif